using Common.Logging;
using System;
using System.Collections.Generic;
namespace AppToolKit.Data
{
	public class SQLClientBuilder : CommandBuilderBase, ICommandBuilder
	{
		private static readonly ILog logger_ = LogManager.GetLogger(typeof(SQLClientBuilder));
		protected override string DoNamedProcess(Dictionary<string, object> dict, string key, DbCommandQuery query)
		{
			string paramName = key;
			if (!query.Parameters.Exists((QueryParameter p1) => p1.Name == paramName))
			{
				QueryParameter queryParameter = new QueryParameter();
				DbTypeMapping dbTypeMapping = new DbTypeMapping();
				queryParameter.Name = paramName;
				if (dict[key] != null)
				{
					queryParameter.Type = dbTypeMapping.From(dict[key]);
					queryParameter.Value = dict[key];
				}
				else
				{
					queryParameter.Value = DBNull.Value;
				}
				query.Parameters.Add(queryParameter);
			}
			return string.Format("@{0}", paramName);
		}
		protected override string DoNumberProcess(string key, object[] args, DbCommandQuery query)
		{
			string paramName = string.Format("p{0}", key);
			if (!query.Parameters.Exists((QueryParameter p1) => p1.Name == paramName))
			{
				QueryParameter queryParameter = new QueryParameter();
				DbTypeMapping dbTypeMapping = new DbTypeMapping();
				queryParameter.Name = paramName;
				object obj = args[Convert.ToInt32(key)];
				if (obj != null)
				{
					queryParameter.Type = dbTypeMapping.From(obj);
					queryParameter.Value = obj;
				}
				else
				{
					queryParameter.Value = DBNull.Value;
				}
				query.Parameters.Add(queryParameter);
			}
			return "@" + paramName;
		}
	}
}
